package cn.lookup;

import cn.lookup.dao.AccountDao;
import cn.lookup.domain.Account;
import cn.lookup.domain.Order;
import cn.lookup.mapper.AccountMapper;
import cn.lookup.mapper.OrderMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.List;

public class AccountTest2 {
    private static SqlSession sqlSession;
    private AccountMapper accountDao;

    @BeforeClass
    public static void  beforeClass() throws IOException {
        InputStream resourceAsStream = Resources.getResourceAsStream("SqlMapperConfig.xml");
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(resourceAsStream);
        sqlSession = build.openSession();
    }
    @Before
    public void before() {
        accountDao = sqlSession.getMapper(AccountMapper.class);
    }
    @After
    public void after() {
        sqlSession.close();
    }

    @Test
    public void findAll() {
        try {
            List<Account> all = accountDao.findAll();
            System.out.println(all);
        } catch (Exception e) {
            System.out.println("报错啦！~~");
        }
    }
    @Test
    public void deleteAccountTest() {
        accountDao.deleteAccount(53);
        sqlSession.commit();
    }
    @Test
    public void queryAccountByIdTest() {
        Account account = accountDao.queryAccountById(1);
        System.out.println(account);
    }
    @Test
    public void queryAccountAndOrdersTest() {
        Account account = accountDao.queryAccountAndOrders(1);
        System.out.println(account);
    }
    @Test
    public void queryAccountAndRolesTest() {
        Account account = accountDao.queryAccountAndRoles(50);
        System.out.println(account);
    }
}
